package com.sxkiler.demo.seata.controller;

import com.sxkiler.demo.seata.service.tcc.TCCOrderService;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/tcc")
public class TCCOrderController {

    @Autowired
    private TCCOrderService orderService;

    @PostMapping("/try")
    public boolean orderTry(@RequestBody BusinessActionContext actionContext,
                            @RequestParam("orderId") Long orderId,
                            @RequestParam("userId") Long userId,
                            @RequestParam("productId") Long productId,
                            @RequestParam("count") Integer count,
                            @RequestParam("payAmount") Integer payAmount){
        return orderService.orderTry(actionContext, orderId, userId, productId, count, payAmount);

    }
    @PostMapping("/confirm")
    public boolean orderConfirm(@RequestBody BusinessActionContext actionContext){
        return orderService.orderConfirm(actionContext);
    }

    @PostMapping("/cancel")
    public boolean orderCancel(@RequestBody BusinessActionContext actionContext){
        return orderService.orderCancel(actionContext);
    }

}
